<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\PinkConfig;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class PinkConfigController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new PinkConfig(['agentPink']), function (Grid $grid) {
            $grid->quickSearch(function ($model, $query) {
                $model->where('houses_name', 'like',"{$query}%");
            });
            $grid->column('id')->sortable();
            $grid->column('image')->image('http://www.sx.com','150','150');
            $grid->column('houses_name');
            $grid->column('agentPink.nick_name','经纪人');
            $grid->column('group_desc');
            $grid->column('site_province');
            $grid->column('site_detail');
            $grid->column('car_number');
            $grid->column('meeting_time');
            $grid->column('phone');
            $grid->status()->switch();
            $grid->column('group_number');
            $grid->column('start_time');
            $grid->column('end_time');
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new PinkConfig(), function (Show $show) {
            $show->field('id');
            $show->field('image')->image();
            $show->field('houses_name');
            $show->field('broker_id');
            $show->field('group_desc');
            $show->field('site_province');
            $show->field('site_detail');
            $show->field('car_number');
            $show->field('meeting_time');
            $show->field('phone');
            $show->field('status');
            $show->field('group_number');
            $show->field('start_time');
            $show->field('end_time');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new PinkConfig(), function (Form $form) {
            $options = [
                '1' =>'经纪人',
                '2' => '卢中原'
            ];
            $form->display('id');
            $form->image('image');
            $form->text('houses_name');
            $form->select('broker_id')->options($options);
            $form->text('group_desc');
            $form->text('site_province');
            $form->text('site_detail');
            $form->text('car_number');
            $form->datetime('meeting_time');
            $form->text('phone');
            $form->switch('status')->customFormat(function ($v){
                return $v == '0' ? '1' : '0';
            })->saving(function ($v){
                return $v ? '1' : '0';
            });
            $form->text('group_number');
            $form->datetime('start_time');
            $form->datetime('end_time');
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
